﻿#include <iostream>
using namespace std;

class A {
public:
    A(int size) : size_(size) {
        data_ = new int[size];
    }

    A() {}

    // 浅拷贝：直接复制指针
    A(const A& a) {
        size_ = a.size_;
        data_ = a.data_;  // 浅拷贝：指针地址被共享
        cout << "shallow copy" << endl;
    }

    ~A() {
        delete[] data_;  // 问题：两个对象会重复释放同一块内存，导致崩溃
    }

    int* data_;
    int size_;
};

int main() {
    A a(10);
    A b = a;  // 浅拷贝
    cout << "b " << b.data_ << endl;
    cout << "a " << a.data_ << endl;
    return 0;
}
